const connection = require('../app/database')
class PermissionService {
  async checkMoment(momentId, id) {
    const statement = 'SELECT * FROM `moment` WHERE id=? AND user_id=?;'
    const [values] = await connection.execute(statement, [momentId, id])
    return !!values.length
  }
  async checkResource(resourceId, resourceName, userId) {
    // console.log(resourceId, resourceName, userId)
    const statement = `SELECT * FROM ${resourceName}  WHERE id=? AND user_id=?;`
    const [values] = await connection.execute(statement, [resourceId, userId])
    return !!values.length
  }
}

module.exports = new PermissionService()
